package com.zhiteng.utils.common;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ZTResult<T> implements Serializable{
	private static final long serialVersionUID = 1L;
	// 响应业务状态
	private int status;  //0：成功 1：失败
	// 响应消息
	private String msg;
	// 响应中的数据
	private T data;
	
	public static <T>ZTResult<T> result(Integer status, String msg, T data){
		return new ZTResult<T>(status, msg, data);
	}
	public static <T>ZTResult<T> result(Integer status, String msg){
		return new ZTResult<T>(status, msg, null);
	}
	public static <T>ZTResult<T> result(Integer status){
		return new ZTResult<T>(status, null, null);
	}
	public static <T>ZTResult<T> result(T data){
		return new ZTResult<T>(0, "ok", data);
	}
	
	
	
	public ZTResult() {
		super();
	}

	public ZTResult(int status, String msg, T data) {
		super();
		this.status = status;
		this.msg = msg;
		this.data = data;
	}




	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	@Override
	public String toString() {
		return "ZTResult [status=" + status + ", msg=" + msg + ", data="
				+ data + "]";
	}
	
	public static void main(String[] args) {
		List<String> list = new ArrayList<>();
		list.add("a");
		ZTResult<List<String>> result = ZTResult.result(2, "ok", list);
		System.out.println(result);
	}
}
